package com.mrobuy.jdvc.controller;

import com.mrobuy.jdvc.Result;
import com.mrobuy.jdvc.dao.TaskDao;
import com.mrobuy.jdvc.dao.VCProductCreateDao;
import com.mrobuy.jdvc.dao.VCProductDao;
import com.mrobuy.jdvc.entity.Item;
import com.mrobuy.jdvc.entity.Task;
import com.mrobuy.jdvc.entity.VCProduct;
import com.mrobuy.jdvc.entity.VCProductCreateTask;
import com.mrobuy.jdvc.service.ItemService;
import com.mrobuy.jdvc.service.ShelvesService;
import com.mrobuy.util.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ItemController {

	@Autowired
	private ItemService itemService;

	@RequestMapping("/item")
	public String item(Model model) {

//		List<VCCategory> categories = vcCategotyDao.list();
//
//		model.addAttribute("categories",categories);

		return "item";
	}


	@RequestMapping("/item/query")
	@ResponseBody
	public Object query(HttpServletRequest request, Item condition) {

		int start = ServletRequestUtils.getIntParameter(request, "start", 1);
		int length = ServletRequestUtils.getIntParameter(request, "length", 10);

		int draw = ServletRequestUtils.getIntParameter(request, "draw", 1);


		Pagination pagination = itemService.load(start, length, condition);

		pagination.setDraw(draw);

		return pagination;
	}
}
